
package com.insigma.business.qrcode.common.converter;

import com.insigma.business.qrcode.soldier.dto.CommonDataDictBSearcher;
import com.insigma.business.qrcode.soldier.entity.CommonDataDictDO;
import com.insigma.business.qrcode.soldier.entity.CommonDataDictDTO;
import com.insigma.business.qrcode.soldier.entity.CommonDataDictSearchRequest;
import com.insigma.business.qrcode.soldier.entity.CommonDataDictUpdateRequest;
import com.insigma.business.qrcode.soldier.request.CommonDataDictInsertRequest;
import org.springframework.beans.BeanUtils;

import java.util.List;


public class CommonDataDictProviderConverter extends AbstractConverter<CommonDataDictDTO, CommonDataDictDO> {

    private final static CommonDataDictProviderConverter commonDataDictConverter = new CommonDataDictProviderConverter();

    private CommonDataDictProviderConverter(){}

    
    public static CommonDataDictBSearcher convertRequestSO2Searcher(final CommonDataDictSearchRequest request){
        final CommonDataDictBSearcher commonDataDictBSearcher = new CommonDataDictBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,commonDataDictBSearcher);
        return commonDataDictBSearcher;
    }

    
    public static CommonDataDictDO convertRequestUO2DO(final CommonDataDictUpdateRequest commonDataDictUpdateRequest) {
        final CommonDataDictDO commonDataDictDO = new CommonDataDictDO();
        BeanUtils.copyProperties(commonDataDictUpdateRequest,commonDataDictDO);
        
        return commonDataDictDO;
    }

    
    public static CommonDataDictDO convertRequestIO2DO(final CommonDataDictInsertRequest commonDataDictInsertRequest) {
        final CommonDataDictDO commonDataDictDO = new CommonDataDictDO();
        BeanUtils.copyProperties(commonDataDictInsertRequest,commonDataDictDO);
        return commonDataDictDO;
    }

    
    public static List<CommonDataDictDTO> convertResponseDOList2DTOList(final List<CommonDataDictDO> commonDataDictDOList){
        return commonDataDictConverter.convertGenericResponseDOList2DTOList(commonDataDictDOList);
    }

    
    public static CommonDataDictDTO convertResponseDO2DTO(final CommonDataDictDO commonDataDictDO){
        return commonDataDictConverter.convertGenericResponseDO2DTO(commonDataDictDO);
    }

    
    @Override
    protected CommonDataDictDTO doConvertResponseDO2DTO(CommonDataDictDO commonDataDictDO) {
        final CommonDataDictDTO commonDataDictDTO = new CommonDataDictDTO();
        try {
            BeanUtils.copyProperties(commonDataDictDO, commonDataDictDTO);
        }catch(RuntimeException be){
            
            return null;
        }
        return commonDataDictDTO;
    }

}
